//
//  XGProgressView.m
//  BSBuDeJie
//
//  Created by monkey on 2019/1/4.
//  Copyright © 2019 itcast. All rights reserved.
//

#import "XGProgressView.h"

@implementation XGProgressView

- (void)drawRect:(CGRect)rect
{
    // 圆心
    CGPoint center = CGPointMake(rect.size.width / 2.f, rect.size.height / 2.f);
    // 半径
    CGFloat radius = MIN(rect.size.width, rect.size.height) / 2.f;
    // 开始弧度
    CGFloat startAngle = -M_PI_2;
    // 结束弧度
    CGFloat endAngle = 2 * M_PI * self.progress + startAngle;
    // 开始绘制
    UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:center radius:radius startAngle:startAngle endAngle:endAngle clockwise:YES];
    [path addLineToPoint:center];
    [path closePath];
    [[UIColor colorWithWhite:1 alpha:0.3] setFill];
    [path fill];
}

- (void)setProgress:(CGFloat)progress
{
    _progress = progress;
    
    // 重绘
    [self setNeedsDisplay];
}

@end
